import requests
from concurrent.futures import ThreadPoolExecutor
from etc.logger import logger


def getPage(id):
    url = 'http://www.tjsql.com/data.aspx?d=%s'%id
    try:
        r = requests.get(url,timeout=5)
        if r.status_code == requests.codes.ok:
            with open('/home/ider/Documents/pages/%s.html'%id,'wb')as f:
                f.write(r.content)
            print('%s : ok'%id)
            return
        else:
            logger.warn(id)
    except Exception as e:
        logger.warn(id)

# falid = [49574,49929]
falid = [36232]
# falid = [82712,82994,83262,83405]
def main():
    pool = ThreadPoolExecutor(2)
    # result_queue = multiprocessing.Queue()
    # for i in range(41942,50000):
    for i in falid:
    # for i in range(50000,171613):
        pool.submit(getPage,str(i))
        # getPage(str(i))

if __name__=='__main__':
    main()
